package com.zjut.multithreading.controller;

import com.zjut.multithreading.service.TimerTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping(value = "/multithreading")
public class TimerTaskController {

    @Autowired
    private TimerTaskService timerTaskService;

    @RequestMapping(value = "/doPing", method = RequestMethod.GET)
    @ResponseBody
    public void doPing() {
        Date CurrentDate =new Date();
        SimpleDateFormat dateFormatDay = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormatTime = new SimpleDateFormat("HH:mm:ss");
        String date = dateFormatDay.format(CurrentDate);
        String time = dateFormatTime.format(CurrentDate);
        timerTaskService.doPing(date, time, String.valueOf(CurrentDate.getHours()));
    }

}
